package HomeWork.Work_02;

/**
 * 分别使用for循环，while循环，do循环求1到100之间所有能被3整除的整数的和。
 */
public class Number_04 {
    public static void main(String[] args){
        For();
        While();
        Do();
    }
    public static void For(){
        int f = 0;
        for(int i = 1; i <= 100; i++){
            if(0 == i % 3){
                f += i;
            }
        }
        System.out.println("和为：" + f);
    }
    public static void While(){
        int w = 0, i = 1;
        while(i <= 100){
            if(0 == i % 3){
                w += i;
            }
            i++;
        }
        System.out.println("和为：" + w);
    }
    public static void Do(){
        int d = 0, i = 1;
        do{
            if(0 == i % 3){
                d += i;
            }
            i++;
        }while(i <= 100);
        System.out.println("和为：" + d);
    }
}
